package com.foreknow.elm.controller;

import javax.servlet.http.HttpServletRequest;
import com.foreknow.elm.po.Deliveryaddress;
import com.foreknow.elm.service.DeliveryAddressService;
import com.foreknow.elm.service.Impl.DeliveryAddressServiceImpl;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

public class DeliveryAddressController {
    public Object listDeliveryAddressByUserId(HttpServletRequest request){
        //获取前台请求参数 /DeliveryAddressController/listDeliveryAddressByUserId?userId=11111111111
        String userId = request.getParameter("userId");
        DeliveryAddressService deliveryAddressService = new DeliveryAddressServiceImpl();
        List<Deliveryaddress> list = deliveryAddressService.listDeliveryAddressByUserId(userId);
        return list;
    }
    public Object getDeliveryAddressById(HttpServletRequest request){
        //获取前台请求参数 /DeliveryAddressController/getDeliveryAddressById?daId=2
        Integer daId = Integer.parseInt(request.getParameter("daId")) ;
        DeliveryAddressService deliveryAddressService = new DeliveryAddressServiceImpl();
        Deliveryaddress deliveryaddresss = deliveryAddressService.getDeliveryAddressById(daId);
        return deliveryaddresss;
    }
    public Object saveDeliveryAddress(HttpServletRequest request){
        //获取前台请求参数 /DeliveryAddressController/saveDeliveryAddress?contactName=李榜怀&contactSex=1&contactTel=24234234&address=北京市中南海&userId=12345671111
        String contactName = request.getParameter("contactName");
        Integer contactSex = Integer.parseInt(request.getParameter("contactSex"));
        String contactTel = request.getParameter("contactTel");
        String address = request.getParameter("address");
        String userId = request.getParameter("userId");
        DeliveryAddressService deliveryAddressService = new DeliveryAddressServiceImpl();
        Integer result = deliveryAddressService.saveDeliveryAddress(contactName,contactSex,contactTel,address,userId);
        return result;
    }
    public Object updateDeliveryAddress(HttpServletRequest request){
        //获取前台请求参数 /DeliveryAddressController/updateDeliveryAddress?daId=15&contactName=董天炜&contactSex=1&contactTel=24234234&address=北京市中南海&userId=12345671111
        Integer daId = Integer.parseInt(request.getParameter("daId")) ;
        String contactName = request.getParameter("contactName");
        Integer contactSex = Integer.parseInt(request.getParameter("contactSex"));
        String contactTel = request.getParameter("contactTel");
        String address = request.getParameter("address");
        String userId = request.getParameter("userId");
        DeliveryAddressService deliveryAddressService = new DeliveryAddressServiceImpl();
        Integer result = deliveryAddressService.updateDeliveryAddress(daId,contactName,contactSex,contactTel,address,userId);
        return result;
    }
    public Object removeDeliveryAddress(HttpServletRequest request){
        //获取前台请求参数 /DeliveryAddressController/removeDeliveryAddress?daId=4
        Integer daId = Integer.parseInt(request.getParameter("daId")) ;
        DeliveryAddressService deliveryAddressService = new DeliveryAddressServiceImpl();
        Integer result = deliveryAddressService.removeDeliveryAddress(daId);
        return result;
    }
}